MKCONF_DIR = ../../mkconfig
LIBC_DIR = ../../libc
UTILS_DIR = ../../utils

include $(MKCONF_DIR)/compile.mk
include $(MKCONF_DIR)/config.mk

#CONF_FILES += $(TOPDIR)/../../utility/configs/$(BOARD)/config.mk
CONF_FILES += $(TOPDIR)/../../base/model/$(BOARD)/config/config.mk


Target = build/sys_$(BOARD)
Middle = $(obj)/sys_$(BOARD)

CPPFLAGS += -I../../utility/include -I../../base/model/$(BOARD)/config
export CPPFLAGS

DIRS := ../../base
DIRS += ../../utility
DIRS += $(LIBC_DIR)

SOBJS-y :=
COBJS-y	:= main.o $(BOARD).o

SRCS := $(COBJS-y:.o=.c)
OBJS := $(addprefix $(obj)/, $(COBJS-y))

NEED_BUILD_INFO := yes

LINKSCRIPT := sh.ld

OBJS += ../../base/build/$(BOARD)/libbase.o
OBJS += ../../utility/build/$(BOARD)/libutility.o
LIBS :=	$(LIBC_DIR)/build/libc_$(ARCH).a

all: $(DIRS) $(Target).bin $(Target).hex

all: signature
signature: $(Target).bin
	@echo Signature the output binary to build/rxsys.bin ...
	@$(UTILS_DIR)/rxDnw --file_path=$< --file_type=0 --result_name=build/rxsys.bin
	@echo Merging the rxBoot and rxSys to $(Target).rxsys.bin ...
	@$(CP) /y $(subst /,\,$(UTILS_DIR)/rxboot.sig.bin) $(subst /,\,$(Target).rxsys.bin)
	@$(DD) bs=4k if=build/rxsys.bin of=$(Target).rxsys.bin seek=2

dwn: $(Target).rxsys.bin
.PHONY:$(Target).rxsys.bin
$(Target).rxsys.bin: $(Target).bin
	@$(UTILS_DIR)/rxDnw --serial=com$(DWN_COMPORT) --file_type=0 --result_name=$(Target).rxsys.bin

dwn1: build/rxsys.bin
.PHONY:build/rxsys.bin
build/rxsys.bin: $(Target).bin
	@$(UTILS_DIR)/rxDnw --serial=com$(DWN_COMPORT) --file_type=0 --result_name=build/rxsys.bin

include $(MKCONF_DIR)/rules.mk
include $(MKCONF_DIR)/operation.mk
